package com.example.neteaseapplication.ui.home;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.neteaseapplication.R;
import com.example.neteaseapplication.entity.Song;

import java.util.List;

public class LocalMusicAdapter extends ArrayAdapter {
    private List<Song> mSongList;
    private Activity mContext;
    private int mResourceId;
    private TextView mTvMusicName;
    private TextView mTvMusicMsg;

    public LocalMusicAdapter(Activity context, int resource, List<Song> songList) {
        super(context, resource, songList);
        mContext = context;
        mResourceId = resource;
        mSongList = songList;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, mResourceId, null);
        }
        mTvMusicName = convertView.findViewById(R.id.tv_music_name);
        mTvMusicMsg = convertView.findViewById(R.id.tv_singer_name);
        Song song = mSongList.get(position);

        String name = song.getName();
        String musicName = name.substring(0, name.length() - 4);
        String singer = song.getSinger();
        mTvMusicName.setText(musicName);
        mTvMusicMsg.setText(singer+"-"+musicName);
        return convertView;
    }
}
